package com.example.demo.controller;

import com.example.demo.model.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController {
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String say(){
         return "hello,springmvc";
    }
    @RequestMapping("/sayHi")
    public String sayHi(){
        return "hi,Spring MVC";
    }
    @RequestMapping("/r1")
    public String r1(String name){
        return "接收到参数，name："+name;
    }
    @RequestMapping("r2")
    public String r2(Student student){
        return student.toString();
    }
    @RequestMapping("/r6")
    public String r6(@RequestParam("name") String userName){
        return "接收到参数，name："+userName;
    }
    @RequestMapping("/r7")
    public String r7(String[] array){
        return "接收到参数，array："+ Arrays.toString(array);
    }
    @RequestMapping("/r8")
    public String r8(@RequestParam List<String> list){
        return "接收到参数，list："+list;
    }

    /**
     * 接收json
     * @param student
     * @return
     */
    @RequestMapping("r9")
    public String r9(@RequestBody Student student){
        return student.toString();
    }

    /**
     * 从路径中获取参数
     * @return
     */
    @RequestMapping("/article/{articleId}")
    public String r10(@PathVariable("articleId") Integer articleId){
        return "接收到参数，articleId:"+articleId;
    }
    /**
     * 从路径中获取参数
     * @return
     */
    @RequestMapping("/article/{articleId}/{name}")
    public String r11(@PathVariable("articleId") Integer articleId,@PathVariable("name")String name){
        return "接收到参数，articleId:"+articleId+"name:"+name;
    }

    /**
     * 上传文件
     * @return
     */
    @RequestMapping("r13")
    public String r13(@RequestPart("file") MultipartFile file){
        String originalFilename= file.getOriginalFilename();
        return "接收到文件："+originalFilename;
    }





}
